//
//  HPUploadSuccessViewController.m
//  HPZZTong
//
//  Created by Handpay on 14-3-30.
//  Copyright (c) 2014年 Handpay. All rights reserved.
//

#import "HPUploadSuccessViewController.h"

@interface HPUploadSuccessViewController ()
@property (retain, nonatomic) IBOutlet UILabel *sucessTitle;

@end

@implementation HPUploadSuccessViewController

#define kSuccessCellHeight  105

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.showBackButton = NO;
    }
    return self;
}

- (void)viewDidLoad
{
    self.title = @"提交成功";
    [super viewDidLoad];
    
    self.successTableView.dataSource = self;
    self.successTableView.delegate = self;
    
    UIView* tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    tempView.backgroundColor = [UIColor clearColor];
    self.successTableView.tableFooterView = tempView;
    [tempView release];
    
    [self.moneyButton setBackgroundImage:[[UIImage imageNamed:@"bluebutton.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0] forState:UIControlStateNormal];
    
    [self.moneyButton setBackgroundImage:[[UIImage imageNamed:@"bluebuttonhover.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0] forState:UIControlStateHighlighted];
    
    [NOTIFICATION addObserver:self selector:@selector(tableBarSelectedIndexChanged:) name:TableBarSelectedIndexChangeNotificationKey object:nil];

    NSString * bindCSN = [self.screenData objectForKey:@"bindCSN"];
    if (bindCSN.length > 0)
    {
        [CSNValidator bindCSN:bindCSN];
    }
    
    if (kVerChannel == VerChannelHeXin) {
        self.sucessTitle.textColor = kTitleTipsColor;
    }
}

- (void)tableBarSelectedIndexChanged:(NSNotification*)notification{
    NSInteger index = [notification.object integerValue];
    if (index > 0) {
        UINavigationController *nav = [self.tabBarController.viewControllers objectAtIndex:0];
        [nav popToRootViewControllerAnimated:NO];
    }
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    [self hideTabBar:NO];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 300, kSuccessCellHeight)];
    label.font = kNormalFont;
    label.textColor = kNormalFontColor;
    label.text = @"您的开通资质材料已成功提交，我们将在3个工作日之内通过手机短信告知您审核结果。在此期间，您可以进行收款操作，资金结算会在审核通过后进行处理。";
    label.numberOfLines = 0;
    [label sizeToFit];
    [cell addSubview:label];
    [label release];
    
    return [cell autorelease];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return kSuccessCellHeight;
}

- (void)dealloc {
    [NOTIFICATION removeObserver:self];
    
    [_successTableView release];
    [_moneyButton release];
    [_sucessTitle release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setSuccessTableView:nil];
    [self setMoneyButton:nil];
    [super viewDidUnload];
}

- (IBAction)moneyButtonClick:(id)sender {
    [SWIPERENG selectSwiperAndGetCsn:^(HPSwiperResult *swiperResult) {
        [CSNValidator validateCSNAndExcuteBlock:^(HPSwiperResult *swiperResult) {
            if (swiperResult.isSuccess)
            {
                [self moneyButtonProcess];
            }
        } autoTip:YES];
    } isShow:NO];
    
}

- (void)moneyButtonProcess
{
    if ([[self.screenData allKeys] containsObject:KEY_SCREEN_NAME]) {
        NSString* scrName = [self.screenData objectForKey:KEY_SCREEN_NAME];
        if (scrName && [scrName isEqualToString:SCR_COLLECT_MONEY]) {
            [HPUIENG popScreenByNum:4];
            return;
        }
    }
    [self.tabBarController setSelectedIndex:1];
    
    UINavigationController *nav = [self.tabBarController.viewControllers objectAtIndex:0];
    [nav popToRootViewControllerAnimated:NO];
}
@end
